import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import dva from 'dva';
import { createBrowserHistory } from 'history';
// 1. initial
function dvaInit(initialState) {
  const app = dva({
    history: createBrowserHistory({basename: '/srd'}),
    initialState: initialState || {},
    onStateChange(res) {
      localStorage.setItem("store",JSON.stringify(res))
    },
    onReducer: r => (state, action) => {
      const newState = r(state, action);
      return newState;
    }
  });
 
  let model = require('./models/app').default
  app.model(model)
  app.router(require('./router').default);
  
  app.start('#root');
}
if(localStorage.getItem('store')){
  dvaInit(JSON.parse(localStorage.getItem('store')))
}else{
   dvaInit(null)
}

serviceWorker.unregister();
